home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH2 / SRC / SCALE.FRM < prev    next >
Text File  |  1995-12-21  |  2KB  |  74 lines

  1. VERSION 4.00
  2. Begin VB.Form ScaleForm 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "Scaling custom coordinates to pixels"
  5.    ClientHeight    =   4140
  6.    ClientLeft      =   2235
  7.    ClientTop       =   1590
  8.    ClientWidth     =   4140
  9.    Height          =   4830
  10.    Left            =   2175
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   -12
  13.    ScaleLeft       =   -1
  14.    ScaleMode       =   0  'User
  15.    ScaleTop        =   11
  16.    ScaleWidth      =   12
  17.    Top             =   960
  18.    Width           =   4260
  19.    Begin VB.Menu mnuFile 
  20.       Caption         =   "&File"
  21.       Begin VB.Menu mnuFileExit 
  22.          Caption         =   "E&xit"
  23.       End
  24.    End
  25. End
  26. Attribute VB_Name = "ScaleForm"
  27. Attribute VB_Creatable = False
  28. Attribute VB_Exposed = False
  29. Option Explicit
  30.  
  31.  
  32. Private Sub Form_Load()
  33. Dim X1 As Integer
  34. Dim Y1 As Integer
  35. Dim X2 As Integer
  36. Dim Y2 As Integer
  37. Dim scale_left As Single
  38. Dim scale_top As Single
  39. Dim pix_per_unit_x As Single
  40. Dim pix_per_unit_y As Single
  41.     
  42.     ' Custom coordinates for the points.
  43.     X1 = 0
  44.     Y1 = 2
  45.     X2 = 10
  46.     Y2 = 8
  47.     
  48.     ' Draw an X.
  49.     Line (X1, Y1)-(X2, Y2)
  50.     Line (X1, Y2)-(X2, Y1)
  51.     
  52.     ' Prepare for translation.
  53.     scale_left = ScaleX(ScaleLeft, ScaleMode, 3)
  54.     scale_top = ScaleY(ScaleTop, ScaleMode, 3)
  55.     pix_per_unit_x = ScaleX(1, ScaleMode, 3)
  56.     pix_per_unit_y = ScaleY(1, ScaleMode, 3)
  57.     
  58.     ' Translate coordinates into pixels.
  59.     X1 = X1 * pix_per_unit_x - scale_left
  60.     Y1 = Y1 * pix_per_unit_y - scale_top
  61.     X2 = X2 * pix_per_unit_x - scale_left
  62.     Y2 = Y2 * pix_per_unit_y - scale_top
  63.     
  64.     ' Draw a box around the X.
  65.     If Rectangle(hDC, X1, Y1, X2, Y2) = 0 Then Exit Sub
  66. End Sub
  67.  
  68.  
  69. Private Sub mnuFileExit_Click()
  70.     Unload Me
  71. End Sub
  72.  
  73.  
  74.